using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class Albums
    {
           #region Common
        public eAlbums   Data;

        public Albums()
        {
            Data = new eAlbums();
		}

        ~Albums()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cAlbums objDAL = new cAlbums();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cAlbums objDAL = new cAlbums();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cAlbums objInfor = new cAlbums(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.AlbumID;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cAlbums objInfor = new cAlbums();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

     

        private void MappingData(cAlbums objInfor)
        {
            try { objInfor.AlbumName1 = Data.AlbumName1; }
            catch { objInfor.AlbumName1 = ""; }
            try { objInfor.AlbumName2 = Data.AlbumName2; }
            catch { objInfor.AlbumName2 = ""; }
           try { objInfor.AlbumName3 = Data.AlbumName3; }
           catch { objInfor.AlbumName3 = ""; }
          try {  objInfor.AlbumImage = Data.AlbumImage; }
          catch { objInfor.AlbumImage = ""; }
            objInfor.DateCreated = Data.DateCreated; 
        }

        private void ConvertData(cAlbums objInfor)
        {
            try { Data.AlbumName1 = objInfor.AlbumName1; }
            catch { Data.AlbumName1 = ""; }
            try {Data.AlbumName2 = objInfor.AlbumName2;}
            catch { Data.AlbumName2 = ""; }
            try {Data.AlbumName3 = objInfor.AlbumName3;}
            catch { Data.AlbumName3 = ""; }
            try { Data.AlbumImage = objInfor.AlbumImage; }
            catch { Data.AlbumImage = ""; }
            Data.DateCreated = objInfor.DateCreated;
        }

        public DataTable Search(int ItemView,string Title, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cAlbums objDAL = new cAlbums();
            tbResult = objDAL.Search(ItemView, Title,PageIndex, PageSize, ref  PageCount);
            return tbResult;
        }

        #endregion
    }
}
